package cn.com.shopec.erp.system.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

/** 
 * @ClassName: User 
 * @Description: 用户表的实体
 * @author: lule
 * @date 2013-5-22 下午6:00:23
 *  
 */
@Entity
@Table(name="tbl_scm_user")
public class User implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3887965762844973927L;
	
	/** 主键. */
	private String id;
	/** 用户名. */
	private String userName;
	/** 用户真实名. */
	private String realName;
	/** 密码. */
	private String pwd;
	/** 用户性质:1-普通用户，2-超级管理员. */
	private int userNature = 1;
	/** 用户状态:1-正常，2-锁定. */
	private int userStatus = 1;
	/** 删除标识:0-已删除，1-未删除. */
	private int deleteFlag = 1;
	/** 用户登录次数限制. */
	private int loginCount = 0;
	/** 用户解锁限制时长. */
	private Date enableTime;
	
	/** 角色. */
	private Set<Role> roles = new HashSet<Role>();
	
	public User() {
		super();
	}
	public User(String id) {
		super();
		this.id = id;
	}
	public User(String id, String userName, String realName, String pwd,
			int userNature, int userStatus, int deleteFlag,int loginCount, Date enableTime,Set<Role> roles) {
		super();
		this.id = id;
		this.userName = userName;
		this.realName = realName;
		this.pwd = pwd;
		this.userNature = userNature;
		this.userStatus = userStatus;
		this.deleteFlag = deleteFlag;
		this.loginCount = loginCount;
		this.enableTime = enableTime;
		this.roles = roles;
	}
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	@Column(name = "user_name")
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	@Column(name = "real_name")
	public String getRealName() {
		return realName;
	}
	public void setRealName(String realName) {
		this.realName = realName;
	}
	@Column(name = "pwd")
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	@Column(name = "user_nature")
	public int getUserNature() {
		return userNature;
	}
	public void setUserNature(int userNature) {
		this.userNature = userNature;
	}
	@Column(name = "user_status")
	public int getUserStatus() {
		return userStatus;
	}
	public void setUserStatus(int userStatus) {
		this.userStatus = userStatus;
	}
	@Column(name = "delete_flag")
	public int getDeleteFlag() {
		return deleteFlag;
	}
	public void setDeleteFlag(int deleteFlag) {
		this.deleteFlag = deleteFlag;
	}
	
	@Column(name = "login_count")
	public int getLoginCount() {
		return loginCount;
	}
	public void setLoginCount(int loginCount) {
		this.loginCount = loginCount;
	}
	@Column(name = "enable_time")
	public Date getEnableTime() {
		return enableTime;
	}
	public void setEnableTime(Date enableTime) {
		this.enableTime = enableTime;
	}
	@ManyToMany
	@JoinTable(name = "tbl_scm_user_role", 
	joinColumns = {@JoinColumn(name = "user_id")},
	inverseJoinColumns = {@JoinColumn(name = "role_id")})
	public Set<Role> getRoles() {
		return roles;
	}
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	
}
